#-*- coding:utf-8 -*-

from ctypes import windll, create_string_buffer
import struct

def get_cmd_width()->int:
    
    win_stdout = -11

    fd = windll.kernel32.GetStdHandle(win_stdout)

    #获得标准输出的句柄

    cstruct = create_string_buffer(22)

    rc_struct = windll.kernel32.GetConsoleScreenBufferInfo(fd, cstruct)

    #获得控制台的属性
    sizex=80
    if rc_struct:


        (bufx, bufy, curx, cury, wattr,
         left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", cstruct)

        sizex = right - left + 1

        sizey = bottom - top + 1

    return sizex

def get_content_from_clipboard(in_str)->list:
    '''
    split the content to paragraphs
    '''
    if '\r\n' in in_str:
        lst = in_str.strip('\r\n').split('.\r\n')
    else:
        lst = in_str.strip('\n').split('.\n')
    out = []
    for ss in lst:
        tmp = ss.replace('\r\n', ' ')
        tmp = tmp.replace('\n', ' ')
        tmp = tmp.replace('\x02','')
        out.append(tmp)
    return out

def format_translate_result(lst)->str:
    out = '.\n'.join(lst)
    return out

if __name__=='__main__':
    print(get_cmd_width())
    test_str='''
Until now, we have mainly considered shape analysis for static object recognition. Another important application for the tools presented is in automatic identification of activities from videos or
motion capture data. A typical approach is to extract the shapes as e.g. the silhouettes of objects
in each frame of a video and make use of the usual tools for comparing shapes. This, however,
requires additional time-series modelling to compare sequences on shape spaces, which may be
solved in very different ways. We will settle to describe one of these approaches, which is given as
a natural extension of the SRVT framework for comparing objects.
A popular way of capturing realistic motions for use in computer animation is through motion
capturing, where the movement of an actor is recorded, and imposed onto a virtual skeleton. In
[21], Eslitzbichler provided an approach to model character animations from motion capture data
as curves on an n-torus. Each point on the curve corresponds to a pose, that may be mapped or
embedded in R
3
. This allows the use of the SRVT of the curves to compare and classify different
movements. In [15], Celledoni et al. provided an extension of the SRVT for Lie group valued
curves, which in turn made it possible to model these character animations directly as curves in
SO(3)n. In [16], the SRVT was further generalized for curves in homogeneous spaces.
'''
    out =  get_content_from_clipboard(test_str)
    print(len(out))
    for s in out:
        print(s)